﻿@{
    ViewBag.Title = "容器返修登记";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<link href="~/Content/css/container_purchaseInstockEdit.css" rel="stylesheet" />

<script type="text/javascript">
    $(function () {
        Index.init();
    });

    var Index = {
        defaultDate: '@ViewData["defaultDate"].ToString()',
        FDocuNO:'@ViewData["FDocuNO"].ToString()',
        curUserName: '@ViewData["curUserName"].ToString()',
        curDate: '@ViewData["curDate"].ToString()',
        dicts:{
            "add":"show1,show2,show3,show5,show7".split(","),
            "bill":"show4,show6,show8".split(",")
        },
        isFormal:false,
        init: function () {
            with (Index) {
                initControl();

                loadDataList($.request("FDocuNO"), $.request("FHappenComNO"), $.request("FDescription_DOC"), $.request("isArchive"), $.request("isDefaultDate"));

                $('select').bindSelect();
            }
        },
        initControl: function () {
            !!($.request("type") in Index.dicts) && (function(){
                var shows = Index.dicts[$.request("type")];

                shows.forEach(function(item){
                    $(".{0}".format(item)).removeClass("shows");
                });
            })();

            $.renderMy97Datepicker();

            $("[my97date]").val(new Date().format("yyyy-MM-dd"));

            $("#FHappenComNO1").bindSelect({
                url: "/WareHouse/Container/GetSupplierJson",
                id: "UnitNO",
                text: "UnitNOShortName"
            });
            
            $("#FDocuTypeNo1").bindSelect({
                url: "/WareHouse/Container/GetDocuType?FTypeNO=RX",
                id: "FTypeNO",
                text: "FTypeNOName"
            });

            $("#FDocuNO1").val(Index.FDocuNO);

            $("#FCreateBy").val(Index.curUserName);

            $("#FAuditingBy").val(Index.curUserName);

            $("#FCreateDate").val(Index.curDate);

            $("#FAuditingDate").val(Index.curDate);

            $("#btnGoAdd1").on("click",function(){
                var url = "/WareHouse/Container/ContainerRepairEditAdd?{0}";

                url = url.format($.param({FCredence:$("#FCredence1").val(),FCurDate:$("#FCurDate1").val(),FDescription_DOC:$("#FDescription_DOC1").val(),FHappenComNO:$("#FHappenComNO1").val(),FDocuNO:$("#FDocuNO1").val(),isFormal:(Index.isFormal?1:0)}));

                $.modalOpen({
                    url: url,
                    width: "900px",
                    height: "600px",
                    close: true,
                    btn: ["确定","关闭"],
                    id:"dlgContainerRepairEditAdd",
                    callBack: function (id,isCancel) {
                        !isCancel && (function(){
                            var cols = "FDescription,FPrice,FQuantity_KP,FStoreSetNO,FStoreNO,FContainerName,FContainerNO,Fcredence,FCurDate,FDocuTypeNo,FDocuNO,FDescription_DOC,FHappenComNO".split(',');
                        
                            var rowData = {};

                            var cc = parent.parent.$("#{0}".format(id)).find("iframe").contents();
                        
                            cols.forEach(function (item) {
                                rowData[item] = cc.find("#{0}".format(item)).val();
                            });

                            rowData["FStoreName"] = cc.find("#FStoreNO option:selected").text();

                            rowData["FQuantity"] = rowData["FQuantity_KP"];

                            rowData["FAmount"] =parseInt(rowData["FQuantity"],10) * parseFloat(rowData["FPrice"]);

                            $("#FHappenComNO1").val(cc.find("#FHappenComNO").val());

                            $("#FDescription_DOC1").val(cc.find("#FDescription_DOC").val());
                        
                            $("#FCurDate1").val(cc.find("#FCurDate").val());
                        
                            $("#FCredence1").val(cc.find("#FCredence").val());

                            $("#gridList1").jqGrid("addRowData",$("#gridList1").getGridParam("reccount"), rowData, "last"); 

                            Index.add(rowData,Index.isFormal);
                        
                            !Index.isFormal && (function(){
                                Index.isFormal = true;

                                $('select').bindSelect();
                            })();
                        })();
                    }
                });
            });

            $("#butnBack1").on("click",function(){
                $.goBack();
            });
        },
        loadDataList: function (FDocuNO, FHappenComNO,FDescription_DOC, isArchive, isDefaultDate) {
            var url = "", postData = {};

            !!FDocuNO && (function () {
                $("#FHappenComNO1").val(FHappenComNO);

                $("#FDescription_DOC1").val(FDescription_DOC);

                $("input,select").prop("disabled", true);

                url = "/WareHouse/Container/GetContainerRepairView";

                postData = { FDocuNO: FDocuNO, isArchive: isArchive, isDefaultDate: isDefaultDate };
            })();

            var $gridList1 = $("#gridList1");

            $gridList1.dataGridForJson({
                url: url,
                height: $(window).height() - 420,
                postData:postData,
                colModel: [
                { label: '选择', name: "", width: 60, align: 'center', sortable: false, formatter: $.checkbox, unformat: $.empty },
                { label: '容器编号', name: 'FContainerNO', width: 120, align: 'left', sortable: false },
                { label: '容器名称', name: 'FContainerName', width: 120, align: 'left', sortable: false },
                { label: '开票<br/>数量', name: 'FQuantity_KP', width: 60, align: 'right', sortable: false },
                { label: '实际<br/>数量', name: 'FQuantity', width: 60, align: 'right', sortable: false },
                { label: '单价<br/>(元)', name: 'FPrice', width: 60, align: 'right', sortable: false },
                { label: '金额<br/>(元)', name: 'FAmount', width: 60, align: 'right', sortable: false },
                { label: '备注说明', name: 'FDescription', width: 160, align: 'left', sortable: false },
                { label: '容器分类隐藏)', name: 'FContainerTypeNO', width: 160, align: 'left', sortable: false, hidden: true },
                { label: '容器分类', name: 'FContainerTypeName', width: 100, align: 'center', sortable: false },
                { label: '仓库编号', name: 'FStoreNO', width: 100, align: 'center', sortable: false },
                { label: '仓库名称', name: 'FStoreName', width: 120, align: 'center', sortable: false },
                { label: '定置编号', name: 'FStoreSetNO', width: 100, align: 'center', sortable: false },
                 { label: '', name: '', width: $(window).width() - 1200, align: 'left', sortable: false }
                ],
                pager: "#gridPager1",
                sortname: 'UseUnit,FAccountDate,FDocuNO',
                sortorder: "asc,asc,DESC",
                viewrecords: true,
                rownumWidth: 50,
                onSelectRow: function (rowId) {

                },
                loadComplete: function (data) {
                    Index.dataList = data;
                }
            });

            $gridList1.jqGrid('setFrozenColumns');

            $gridList1.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        },
        add:function(data,foo){
            var postData = {FDocuTypeNO:$("#FDocuTypeNo1").val(),FDouBarCode:"",FDescription2:data["FDescription"],FAccountDate:Index.defaultDate,FCredence:$("#FCredence1").val(),FCurDate:$("#FCurDate1").val(),FHappenComNO:$("#FHappenComNO1").val(),FDescription_DOC:$("#FDescription_DOC1").val()};
            //FDocuTypeNO
            $.extend(postData,data);
            
            postData["FItemDesc"] ="容器采购";

            postData["FDescription"] = postData["FDescription_DOC"];

            !foo && (postData["FDocuNO"]="");

            $.post("/WareHouse/Container/UpdateContainerRepairDetails", { postData: JSON.stringify(postData) }, function (res) {
                var status = parseInt(res["resultState"],10);

                !status && (function(){
                    console.log("插入操作执行失败！");

                    Index.isFormal = false;
                })();
                
                !!status && (function(){
                    console.log("插入操作执行成功，返回单号为：{0}".format(res["DocumentNum"]));
                    
                    $("#FDocuNO1").val(res["DocumentNum"]);
                })();
            },"json");
        }
    };
</script>

<div class="layout" id="layout" style="height: 100%; width: 100%;">
    <h1>容器返修单</h1>
    <header>
        <div class="btn-group">
            <a id="btnGoAdd1" class="btn btn-primary center-block shows show1"><span class="glyphicon glyphicon-plus"></span>&nbsp;新增</a>
            <a id="butnDelete1" class="btn btn-primary center-block  shows show2"><span class="glyphicon glyphicon-trash"></span>&nbsp;	删除</a>
            <a id="butnBack1" class="btn btn-primary center-block r1 r17"><span class="glyphicon glyphicon-chevron-left"></span>&nbsp;	返回</a>
        </div>
        <aside class="shows show3">输入</aside>
        <aside class="shows show4">单据</aside>
    </header>
    <section class="container">
        <section>
            <div class="col">
                <label>返修单位</label>
                <select id="FHappenComNO1" name="" class="form-control">
                    <option value="">==请选择==</option>
                </select>
            </div>
            <div class="col">
                <label>发生方式</label>
                <select id="FDocuTypeNo1" name="" class="form-control">
                </select>
            </div>
            <div class="col">
                <label>摘要说明</label>
                <input id="FDescription_DOC1" name="" placeholder="" type="text" class="form-control required" />
            </div>
        </section>
        <aside>
            <div class="col">
                <label>
                    单据编号		
                </label>
                <input id="FDocuNO1" name="" placeholder="" type="text" class="form-control required" />
            </div>
            <div class="col">
                <label>单据日期</label>
                <input id="FCurDate1" name="" placeholder="" type="text" class="form-control required" my97date="yyyy-mm-dd" />
            </div>
            <div class="col">
                <label>凭证编号</label>
                <input id="FCredence1" name="" placeholder="" type="text" class="form-control required" />
            </div>
        </aside>
    </section>
    <div class="grid_list_1_c">
        <table id="gridList1"></table>
        <div id="gridPager1"></div>
    </div>
    <section class="container col_label">
        <section>
            <div class="col shows show5">
                <label>输入人员</label>
                <input id="FCreateBy" name="" placeholder="" type="text" class="form-control required input_b" readonly="readonly" />
            </div>
            <div class="col shows show6">
                <label>审核人员</label>
                <input id="FAuditingBy" name="" placeholder="" type="text" class="form-control required input_b" readonly="readonly" />
            </div>
            <div class="col shows show7">
                <label>输入日期</label>
                <input id="FCreateDate" name="" placeholder="" type="text" class="form-control required input_b" readonly="readonly" />
            </div>
            <div class="col shows show8">
                <label>审核日期</label>
                <input id="FAuditingDate" name="" placeholder="" type="text" class="form-control required input_b" readonly="readonly" />
            </div>
        </section>
    </section>
</div>

